package com.dataex.frame;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

/**
 * 项目名称:xml读取转换工具 类名:IndexJFrame 类描述:主界面类 创建人:马增群 修改备注:
 * 
 * @version 1.0.0
 */
public class IndexFrame extends JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private JMenuBar menuBar = null;

	private JMenu fileMenu = null;
	private JMenu helpMenu = null;

	private JMenuItem existMenuItem = null;
	private JMenuItem importMenuItem = null;
	private JMenuItem exportMenuItem = null;

	private JMenuItem about = null;
	private JMenuItem contact = null;
	private JMenuItem introduce = null;

	private final static String BASEURL = "../xmlDemo/images/";

	// 构造函数，用于初始

	private String arrs2[];

	public static void main(String[] args) {
		System.out.println("启动中.............");
		new IndexFrame();
	}

	public IndexFrame() {

		setTitle("xml转换工具");
		Image image = Toolkit.getDefaultToolkit().getImage(BASEURL + "logo.png");
		setIconImage(image);

		setLocationRelativeTo(null);

		createMenuBar();

		/**/

		setJMenuBar(menuBar);
		// getContentPane().add("Center",splitPane);

		// 设置JFrame的属性
		setResizable(false);// 设置不可以改变大小
		pack();// 自动调整
		setSize(400, 600);
		// setSize(bg.getIconWidth(), bg.getIconHeight());

		// 设置运行时窗口的位置
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension frameSize = getSize();
		if (frameSize.height > screenSize.height) {
			frameSize.height = screenSize.height;
		}
		if (frameSize.width > screenSize.width) {
			frameSize.width = screenSize.width;
		}
		setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
		setVisible(true);
	}

	/**
	 * 方法说明:创建菜单栏
	 */
	public void createMenuBar() {

		menuBar = new JMenuBar();
		menuBar.setBackground(new Color(197, 228, 251));

		fileMenu = new JMenu("文件");
		helpMenu = new JMenu("帮助");

		// ImageIcon conImage=new ImageIcon(BASEURL+"contact.png");
		contact = new JMenuItem("联系");
		about = new JMenuItem("关于");
		introduce = new JMenuItem("说明");

		exportMenuItem = new JMenuItem("xml导出");

		exportMenuItem.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				try {
					new ExportFrame();
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});

		importMenuItem = new JMenuItem("xml导入");

		importMenuItem.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				new ImportFrame();
			}
		});
		existMenuItem = new JMenuItem("退出软件");

		helpMenu.add(contact);
		helpMenu.add(about);
		helpMenu.add(introduce);

		fileMenu.add(exportMenuItem);
		fileMenu.add(importMenuItem);
		fileMenu.add(existMenuItem);

		menuBar.add(fileMenu);
		menuBar.add(helpMenu);
	}

}
